const app = require('./app');

let childProcess = require('child_process');
let path = require('path');

let koaStatic =require('koa-static')

let assert = require('assert');

let {historyApiFallback}=require('koa2-connect-history-api-fallback')

let bodyParser = require('koa-bodyparser');
// let timeMiddleware = require('./middleware/timeMiddleware');

// app.use(timeMiddleware());
let koaRouter = require('./routes/router_config')
let whiteList = koaRouter.filter(item=>item.url !== 'login').map(item=>item.url)

app.use(bodyParser());
app.use(historyApiFallback({
  whiteList
}))
app.use(koaStatic(path.join(__dirname, './public')))

let router = require('./routes/router_index');


// 将koaRouter 当做koa中间件
app.use(router.routes());

let port = 5210;
app.listen(port, () => {
  // childProcess.exec(`start http://localhost:${port}`);
  process.stdout.write(`server running at  http://localhost:${port}\n`)
});
